﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.NHibernateHelper;
using Domain.Entity;
using DataAccess.AbstractRepository;
using NHibernate;

namespace DataAccess.Repository
{
    public class InvoiceRepository : NHibRepository<Invoice>, IInvoiceRepository
    {
        public InvoiceRepository(NHibContext context)
            : base(context)
        {
        }

        public IList<Invoice> GetAllInvoices(DateTime fromDate, DateTime toDate)
        {
            string hsql = "from Invoice where CreatedDate >= " + fromDate + " and " + "CreatedDate < " + toDate.AddDays(1);
            IQuery query = Session.CreateQuery(hsql);
            return query.List<Invoice>();
        }

        public IList<Invoice> GetAllInvoices(long customerID, DateTime fromDate, DateTime toDate)
        {
            string hsql = "select jb.Invoice from JobBooking jb where jb.Customer.ID = " + customerID + " and jb.Invoice.CreatedDate >= " + fromDate + " and " + " jb.Invoice.CreatedDate < " + toDate.AddDays(1);
            IQuery query = Session.CreateQuery(hsql);
            return query.List<Invoice>();
        }
    }
}
